import thread_socket
import user_class
from myoutput import *
#主进程执行
def Front():
    Application_start()
    while(True):
        illegalFlag:bool=False
        str_input=input()
        words:list[str]=str_input.split(" ")
        if(words[0]=="q" or words[0]=="quit"):
            Application_quit()
            break
        elif(words[0]=="h" or words[0]=="help"):
            Application_help()
        elif(words[0]=="s" or words[0]=="show"):
            illegalFlag=Application_show(words)
        else:
            illegalFlag=True
        if(illegalFlag):
            print("\033[91mIllegal import!\033[0m")
#开始应用，启动socket线程
def Application_start():
    Application_showLogo()
    print("\033[37mRoboHero Server\033[0m")
    print("\033[92minput 'h' or 'help' can watch help document\033[0m")
    print("\033[92minput 'q' or 'quit' can quit\033[0m")
    thread_socket.thread_socket_start()
#退出应用
def Application_quit():
    
    for uid in user_class.User_Dict:
        user_class.User_Dict[uid].thread_flag=False
    while(len(user_class.User_Dict)!=0):
        pass
    thread_socket.thread_socket_end()
    thread_socket.Mysocket.close()
    
    
    print("\033[92mPlease wait...\033[0m")
    #exit()
#展示字符画LOGO
def Application_showLogo():
    with open('doc/temp','r') as f:
        for line in f:
            print(line,end="")
        f.close()
#展示帮助文档
def Application_help():
    with open('doc/helpdoc','r') as f:
        for line in f:
            print(line,end="")
        f.close()
#show命令
def Application_show(words:list[str])->bool:
    illegalFlag:bool=False
    if(len(words)==1):
        print("show all players name")#补全
    else:
        if(words[1]=="player"):
            print("show all players message")#补全
        elif(words[1]=="socket"):
            print("show all sockets message")#补全
        else:
            illegalFlag=True
    return illegalFlag
